<?php
$uid = $_SESSION['tcADMINID'];

if(isset($_POST['save_approval']))
{
			$item = $_POST['item'];
			$desc = $_POST['desc'];
			$realestate = $_POST['realestate'];
			$business = $_POST['business'];
			$jobs = $_POST['jobs'];
			$motorvehicles = $_POST['motorvehicles'];
			$announcements = $_POST['announcements'];
			$other = $_POST['other'];
			$contactemail = $_POST['contactemail'];
			$showcontactemail = $_POST['showcontactemail'];
			$address1 = $_POST['address1'];
			$address2 = $_POST['address2'];
			$city = $_POST['city'];
			$state = $_POST['state'];
			$postcode = $_POST['postcode'];
			$phone = $_POST['phone'];
			$fax = $_POST['fax'];
			$businessdesc = $_POST['businessdesc'];
			$listinglevel = $_POST['listinglevel'];
			
			if($listinglevel == 1)
			{
				$amount = 10;
				$duration = 28;
			}
			else
			{
				$amount = 15;
				$duration = 28;
			}
			
			$cat = $realestate;
			if($business != "")
			{
				if($cat == "") $cat = $business;
				else $cat = $cat.",".$business;
			}
			if($jobs != "")
			{
				if($cat == "") $cat = $jobs;
				else $cat = $cat.",".$jobs;
			}
			if($motorvehicles != "")
			{
				if($cat == "") $cat = $motorvehicles;
				else $cat = $cat.",".$motorvehicles;
			}
			if($announcements != "")
			{
				if($cat == "") $cat = $announcements;
				else $cat = $cat.",".$announcements;
			}
			if($other != "")
			{
				if($cat == "") $cat = $other;
				else $cat = $cat.",".$other;
			}
			
			
			$path = "../adimages/";
			$thumb_path = "../adimages/thumb/";
			$imageformaterror = 0;
			$tempimage1 = $_FILES['tempimage1']['name'];
			$tempimage2 = $_FILES['tempimage2']['name'];
			$tempimage3 = $_FILES['tempimage3']['name'];
			$tempimage4 = $_FILES['tempimage4']['name'];
			$tempimage5 = $_FILES['tempimage5']['name'];
			$tempimage6 = $_FILES['tempimage6']['name'];
			
			if($tempimage1 != "")
			{	
				if($_FILES['tempimage1']['type'] == "image/gif" || $_FILES['tempimage1']['type'] == "image/pjpeg" || $_FILES['tempimage1']['type'] == "image/jpeg")
				{
					
						//move_uploaded_file($_FILES['tempimage1']['tmp_name'],$path.$tempimage1);
						$fname = $uid.'tempimage1'.time();
						if($_FILES['tempimage1']['type'] == "image/gif") $filetype = ".gif";
						else  $filetype = ".jpg";
						
						$newupload = $_FILES['tempimage1']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						if($width > 800)
						{
							$newwidth=800;
							$w=$width/$newwidth;
							$newheight=$height/$w;
						}
						if($height > 600)
						{
							$newheight = 600;	
							$h = $height/$newheight;
							$newwidth = $width/$h;
						}
						if($width <= 800) $newwidth = $width;
						if($height <= 600) $newheight = $height;
						
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						//$path = $thumb_path;
						$newupload = $_FILES['tempimage1']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						$newwidth=150;
							
							$w=$width/$newwidth;
							$newheight=$height/$w;
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $thumb_path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						$tempimage1 = $photo1;
				}
				else
				{
					$imageformaterror = 1;	
				}
			}
			if($tempimage2 != "")
			{
				if($_FILES['tempimage2']['type'] == "image/gif" || $_FILES['tempimage2']['type'] == "image/pjpeg" || $_FILES['tempimage2']['type'] == "image/jpeg")
				{
					//move_uploaded_file($_FILES['tempimage2']['tmp_name'],$path.$tempimage2);
					if($_FILES['tempimage2']['type'] == "image/gif") $filetype = ".gif";
						else  $filetype = ".jpg";
						$fname = $uid.'tempimage2'.time();
						$newupload = $_FILES['tempimage2']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						if($width > 800)
						{
							$newwidth=800;
							$w=$width/$newwidth;
							$newheight=$height/$w;
						}
						if($height > 600)
						{
							$newheight = 600;	
							$h = $height/$newheight;
							$newwidth = $width/$h;
						}
						if($width <= 800) $newwidth = $width;
						if($height <= 600) $newheight = $height;
						
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						//$path = $thumb_path;
						$newupload = $_FILES['tempimage2']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						$newwidth=150;
							
							$w=$width/$newwidth;
							$newheight=$height/$w;
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $thumb_path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						$tempimage2 = $photo1;
				}
				else
				{
					$imageformaterror = 1;	
				}
			}
			if($tempimage3 != "")
			{
				if($_FILES['tempimage3']['type'] == "image/gif" || $_FILES['tempimage3']['type'] == "image/pjpeg" || $_FILES['tempimage3']['type'] == "image/jpeg")
				{
					//move_uploaded_file($_FILES['tempimage3']['tmp_name'],$path.$tempimage3);
					if($_FILES['tempimage3']['type'] == "image/gif") $filetype = ".gif";
						else  $filetype = ".jpg";
						$fname = $uid.'tempimage3'.time();
						$newupload = $_FILES['tempimage3']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						if($width > 800)
						{
							$newwidth=800;
							$w=$width/$newwidth;
							$newheight=$height/$w;
						}
						if($height > 600)
						{
							$newheight = 600;	
							$h = $height/$newheight;
							$newwidth = $width/$h;
						}
						if($width <= 800) $newwidth = $width;
						if($height <= 600) $newheight = $height;
						
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						//$path = $thumb_path;
						$newupload = $_FILES['tempimage3']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						$newwidth=150;
							
							$w=$width/$newwidth;
							$newheight=$height/$w;
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $thumb_path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						$tempimage3 = $photo1;
				}
				else
				{
					$imageformaterror = 1;	
				}
			}
			if($tempimage4 != "")
			{
				if($_FILES['tempimage4']['type'] == "image/gif" || $_FILES['tempimage4']['type'] == "image/pjpeg" || $_FILES['tempimage4']['type'] == "image/jpeg")
				{
					//move_uploaded_file($_FILES['tempimage4']['tmp_name'],$path.$tempimage4);
					if($_FILES['tempimage4']['type'] == "image/gif") $filetype = ".gif";
						else  $filetype = ".jpg";
						$fname = $uid.'tempimage4'.time();
						$newupload = $_FILES['tempimage1']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						if($width > 800)
						{
							$newwidth=800;
							$w=$width/$newwidth;
							$newheight=$height/$w;
						}
						if($height > 600)
						{
							$newheight = 600;	
							$h = $height/$newheight;
							$newwidth = $width/$h;
						}
						if($width <= 800) $newwidth = $width;
						if($height <= 600) $newheight = $height;
						
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						//$path = $thumb_path;
						$newupload = $_FILES['tempimage4']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						$newwidth=150;
							
							$w=$width/$newwidth;
							$newheight=$height/$w;
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $thumb_path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						$tempimage4 = $photo1;
				}
				else
				{
					$imageformaterror = 1;	
				}
			}
			if($tempimage5 != "")
			{
				if($_FILES['tempimage5']['type'] == "image/gif" || $_FILES['tempimage5']['type'] == "image/pjpeg" || $_FILES['tempimage5']['type'] == "image/jpeg")
				{
					//move_uploaded_file($_FILES['tempimage5']['tmp_name'],$path.$tempimage5);
					if($_FILES['tempimage5']['type'] == "image/gif") $filetype = ".gif";
						else  $filetype = ".jpg";
						$fname = $uid.'tempimage5'.time();
						$newupload = $_FILES['tempimage5']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						if($width > 800)
						{
							$newwidth=800;
							$w=$width/$newwidth;
							$newheight=$height/$w;
						}
						if($height > 600)
						{
							$newheight = 600;	
							$h = $height/$newheight;
							$newwidth = $width/$h;
						}
						if($width <= 800) $newwidth = $width;
						if($height <= 600) $newheight = $height;
						
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						//$path = $thumb_path;
						$newupload = $_FILES['tempimage5']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						$newwidth=150;
							
							$w=$width/$newwidth;
							$newheight=$height/$w;
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $thumb_path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						$tempimage5 = $photo1;
				}
				else
				{
					$imageformaterror = 1;	
				}
			}
			if($tempimage6 != "")
			{
				if($_FILES['tempimage6']['type'] == "image/gif" || $_FILES['tempimage6']['type'] == "image/pjpeg" || $_FILES['tempimage6']['type'] == "image/jpeg")
				{
					//move_uploaded_file($_FILES['tempimage6']['tmp_name'],$path.$tempimage6);
					if($_FILES['tempimage6']['type'] == "image/gif") $filetype = ".gif";
						else  $filetype = ".jpg";
						$fname = $uid.'tempimage6'.time();
						$newupload = $_FILES['tempimage6']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						if($width > 800)
						{
							$newwidth=800;
							$w=$width/$newwidth;
							$newheight=$height/$w;
						}
						if($height > 600)
						{
							$newheight = 600;	
							$h = $height/$newheight;
							$newwidth = $width/$h;
						}
						if($width <= 800) $newwidth = $width;
						if($height <= 600) $newheight = $height;
						
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						//$path = $thumb_path;
						$newupload = $_FILES['tempimage6']['tmp_name']; 
						if($filetype==".gif") $src = imagecreatefromgif($newupload);
						else $src = imagecreatefromjpeg($newupload);
						list($width,$height)=getimagesize($newupload);
						$newwidth=150;
							
							$w=$width/$newwidth;
							$newheight=$height/$w;
						$tmp=imagecreatetruecolor($newwidth,$newheight);
						imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
						$photo1  = $fname.$filetype;
						$filename = $thumb_path.$photo1; 
						if($filetype==".gif") imagegif($tmp,$filename,100);
						else imagejpeg($tmp,$filename,100);
						imagedestroy($src);
						imagedestroy($tmp);
						
						$tempimage6 = $photo1;
				}
				else
				{
					$imageformaterror = 1;	
				}
			}
			
			if($imageformaterror == 0)
			{
				$cust = time();
				mysql_query("insert into ads (Item, Description, Category, ListingLevel, TempImage1, TempImage2, TempImage3, TempImage4, TempImage5, TempImage6, ContactEmail, ShowEmail, Address1, Address2, City, State, Postcode, Phone, Fax, BusinessDesc, InsertedBy, InsertedDate,TransactionId,TotalAmount, Duration, Cust, Status) values('$item', '$desc', '$cat', '$listinglevel', '$tempimage1', '$tempimage2', '$tempimage3', '$tempimage4', '$tempimage5', '$tempimage6', '$contactemail', '$showcontactemail', '$address1', '$address2', '$city', '$state', '$postcode', '$phone', '$fax', '$businessdesc', '$uid', now(),'submitted by admin', '$amount', '$duration', '$cust', 1)");
				
				$lastinsertid = mysql_insert_id();
				
				
				$e = mysql_fetch_array(mysql_query("select * from users where Id='$uid'"));
						$email = "ida@ecstasoft.com";;
						$from = "From: <$email>";
							$to = $TC_Email;
							$subject = "New Ad is submitted in Study sage";
							$message = "
			Hello,
			
			A new Ad is submitted in Study sage.
			
			Submited By:".$e['FirstName']." ".$e['LastName']."
			
			Please login using the below link to approve it.
			
			".$pathu_admin."
			
			";
						
							mail($to, $subject, $message, $from);
							
							//header("location:index.php?tc=ads_add&_s=T&_s=1");
							echo "<script>window.location='index.php?tc=ads_add&_s=T&_s=1'</script>";
		
							
				//to paypal
				
				?>
				
				<?php /*?><form method="post" action="paypal/process.php" name="credits">
                    <input type="hidden" name="userid" value="<?php echo $uid;?>">
                    <input type="hidden" name="custom_field" value="<?php echo $uid;?>">
                    <input type="hidden" name="invoice" value="<?php echo $lastinsertid;?>">
                    <input type="hidden" name="amount" value="<?php echo number_format($amount,2);?>">
                    <input type="hidden" name="item_name" value="TENNANTCREEKONLINE.com">
                    <div style="display:none">
                    <input type="submit" />
                    </div>
                </form>
				
				<script language="javascript" type="text/javascript">
					document.credits.submit();
				</script><?php */?>
				
				
			<?php 
			}
			else
			{
				//header("location:index.php?tc=ads_add&_s=T&_e=1");
				echo "<script>window.location='index.php?tc=ads_add&_s=T&_e=1'</script>";
			}
}
?>